﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Order3 : System.Web.UI.Page
{

    MyDataDataContext db = new MyDataDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)//用户未登录，返回登录界面
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            //按钮字体颜色变化
            LinkButton3.ForeColor = System.Drawing.Color.SteelBlue;
            //页面首次加载且订单ID不为空
            MyDataDataContext db = new MyDataDataContext();
            //获取要显示的记录对象

            var order = from r in db.Order
                        join u in db.User on r.SellerID equals u.UserID
                        join g in db.SaleOfGoods on r.GoodsID equals g.GoodsID
                        where r.StateOfOrder == -1 & r.BuyerID == Session["UserId"].ToString()//1表示订单处于进行中状态，0表示订单已完成, -1表示失败                                                                                               
                        select new
                        {
                            r.OrderID,
                            u.UserNickname,
                            r.GoodsName,
                            g.Type,
                            r.Price,
                            g.GoodsPicture,
                            r.Time
                        };//映射需要显示的字段

            gvSaleOfGoods.DataSource = order;
            gvSaleOfGoods.DataBind();
            if (gvSaleOfGoods.Rows.Count != 0)
            {

                lblCart.Text = "";
            }
            else
            {

                lblCart.Text = "无失败的订单！";
            }
        }

    }

    protected void GridView2_OnRowCommang(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Del")
        {

            string order1ID = e.CommandArgument.ToString();//获取需要的OrderID用于获取订单记录

            //获取想要确定收货的订单记录
            Order order1 = (from r in db.Order
                            where r.OrderID == order1ID
                            select r).FirstOrDefault();

            db.Order.DeleteOnSubmit(order1);
            //提交
            db.SubmitChanges();


            Response.Write("<script language='javascript'>");
            Response.Write("alert('删除订单成功);");
            Response.Write("</script>");

            //返回信息列表页面
            Response.Redirect("Order3.aspx");



        }       

    }
    protected void drop1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //下拉列表选择买入还是卖出，显示相应订单
        if (Item.Items[0].Selected)
            Response.Redirect("Order1.aspx");

        if (Item.Items[1].Selected)
            Response.Redirect("Order4.aspx");
    }
}
